// 环境检测
const isDevelopment = import.meta.env.DEV;

// 服务器配置 - 使用hostname方式，便于通过hosts文件修改IP
const SERVER_CONFIG = {
  // 生产环境服务器配置
  PRODUCTION: {
    HOST: '192.168.0.108',// 使用hostname，可通过hosts文件修改IP
    PORT: 18080,            // 端口号 - 修改为实际可用的端口
    PROTOCOL: 'http'        // 协议
  },

//   // 开发环境服务器配置
//   DEVELOPMENT: {
//     HOST: 'localhost',
//     PORT: 5174,
//     PROTOCOL: 'http'
//   }
// };
// 服务器配置 - 使用hostname方式，便于通过hosts文件修改IP
// const SERVER_CONFIG = {
//   // 生产环境服务器配置
//   PRODUCTION: {
//     HOST: 'java.cjxt.com',  // 使用hostname，可通过hosts文件修改IP
//     PORT: 18080,            // 端口号 - 修改为实际可用的端口
//     PROTOCOL: 'http'        // 协议
//   },

  // 开发环境服务器配置
  DEVELOPMENT: {
    HOST: 'localhost',
    PORT: 5174,
    PROTOCOL: 'http'
  }
};
// 获取当前环境的服务器配置
const getServerConfig = () => {
  if (isDevelopment) {
    return SERVER_CONFIG.DEVELOPMENT;
  }
  return SERVER_CONFIG.PRODUCTION;
};
// 构建API基础URL
const buildBaseUrl = () => {
  const config = getServerConfig();
  if (isDevelopment) {
    // 开发环境使用代理
    return "/api";
  } else {
    // 生产环境使用完整URL
    return `${config.PROTOCOL}://${config.HOST}:${config.PORT}`;
  }
};

// API配置文件
export const API_CONFIG = {
  // 基础URL - 根据环境使用不同的配置
  BASE_URL: buildBaseUrl(),
  //IMAGE_URL:'http://java.cjxt.com:18080',
  IMAGE_URL:'http://192.168.0.108:18080',
  // 服务器配置信息（用于调试和显示）
  SERVER_INFO: getServerConfig(),

  // 请求超时时间（毫秒）
  TIMEOUT: 1800000,

  // 请求头配置 - 只使用浏览器允许的头部
  HEADERS: {
    "Content-Type": "application/json",
    Accept: "*/*",
  },

  // 接口路径配置
  ENDPOINTS: {
    // 视频流管理
    VIDEO_STREAM_ADD: "/system/videoStream/add",
    VIDEO_STREAM_LIST: "/system/videoStream/list",
    VIDEO_STREAM_UPDATE: "/system/videoStream/edit",
    VIDEO_STREAM_DELETE: "/system/videoStream/remove",
    VIDEO_EDIT_LIST: "/system/videoData/getStoragePath",
    VIDEO_DATA_CUT: "/system/videoSave/cutVideo",
    VIDEO_DATA_CONCAT: "/system/videoSave/mergeVideos",
    // 任务管理
    TASK_LIST: "/system/videoTask/list",
    TASK_ADD: "/system/videoTask/add",
    TASK_UPDATE: "/system/videoTask/edit",
    TASK_DELETE: "/system/videoTask/remove",
    TASK_DROPDOWN: "/system/videoTask/dropdown",
    TASK_EXPORT: "/system/videoTask/exportVideoDataTaskNew",
    TASK_IMPORT: "/system/videoTask/importVideoDataTask",

    // 数据管理
    DATA_LIST: "/system/videoData/list",
    DATA_ADD_LIST: "/system/videoTask/addAnaDataLog",
    DATA_VIDEO_LIST: "/system/videoTask/getDataLogById",
    DATA_SAVE: "/system/data/save",
    DATA_DELETE: "/system/videoData/remove",
    DATA_DROPDOWN: "/system/videoData/selectData",
    DATA_ARCHIVE: "/system/taskDataRel/add",
    DATA_EXPORT: "/system/videoData/export",

    // 数据采集
    COLLECTION_START: "/system/collection/start",
    COLLECTION_STOP: "/system/collection/stop",
    COLLECTION_STATUS: "/system/collection/status",

    // 视频采集
    VIDEO_SAVE_START: "/system/videoSave/startSave",
    VIDEO_SAVE_STOP: "/system/videoSave/stopSave",
    VIDEO_DELETE_DATA: "/system/videoSave/deleteData",

    // 遥测数据
    TELEMETRY_DATA: "/system/telemetry/data",
    TELEMETRY_SAVE: "/system/telemetry/save",

    // 视频数据
    VIDEO_DATA_ADD: "/system/videoData/add",
    VIDEO_FILE_ADD: "/system/videoSave/upload",


    // 文件管理
    FILE_UPLOAD: "/system/file/upload",
    FILE_DOWNLOAD: "/system/file/download",
    FILE_LIST: "/system/file/list",
    PATH_PACKAGING_COMPRESSION_DOWNLOAD: "/system/videoTask/pathPackagingCompressionDownload",

    // 系统配置
    SYSTEM_CONFIG: "/system/config",
    SYSTEM_STATUS: "/system/status",

    //退出登录
    LOGOUT: "/admin/user/logOut",
    CAPTCHA: "/admin/user/captcha",
    //登录
    LOGIN: "/admin/user/login",
    //修改密码
    UPDATE_PASSWORD: "/admin/user/updatePassWord",
    //管理员管理
    ADMIN_LIST: "/admin/user/getAdminList",
    ADMIN_LIST_ALL: "/admin/user/getAdminNoPageList",
    ADMIN_SAVE: "/admin/user/addAndUpdateAdmin",
    ADMIN_DELETE: "/admin/user/delAdmin",
    ADMIN_DETAIL: "/admin/user/getAdminById",
    //任务类型
    TASK_TYPE_LIST:"/admin/taskType/list",
    TELEMETRY_TYPE_LIST:"/admin/taskType/getTelemetryListByTaskTypeId",
    TASK_TYPE_SAVE:"/admin/taskType/add",
    TASK_TYPE_EDIT:"/admin/taskType/edit",
    TASK_TYPE_DELETE:"/admin/taskType/delete",
    TASK_TYPE_DETAIL:"/admin/taskType/detail",
    TASK_PULL_DOWN_LIST:"/admin/taskType/pullDownList",
    //遥测数据参数类型telemetryData
    TELEMETRY_DATA_LIST:"/admin/telemetry/list",
    TELEMETRY_DATA_SAVE: "/admin/telemetry/add",
    TELEMETRY_DATA_DELETE: "/admin/telemetry/delete",
    ADD_TELEMETRY_data: "/system/videoData/saveTelemetryData",
    UPDATE_TELEMETRY_TYPE: "/system/videoData/updateTelemetryData",
    BATCH_SAVE_TELEMETRY_DATA: "/system/videoData/batchSaveTelemetryData",
    SAVE_OR_CANCEL_TELEMETRY: "/system/videoData/saveOrCancelTelemetry",
    //获取遥测数据文件保存路径
    GET_TELEMETRY_STORAGE_PATH: "/system/videoData/getTelemetryStoragePath",
    //编辑遥测数据文件保存路径
    EDIT_TELEMETRY_DATA: "/system/videoData/editTelemetryData",
    //上传遥测数据文件
    UPLOAD_TELEMETRY_TXT: "/system/videoData/uploadTxt",
    //结果快报模板
    RESULT_REPORT_TEMPLATE_LIST:"/resultTemplate/getResultTemplateList",
    RESULT_REPORT_TEMPLATE_SAVE:"/resultTemplate/saveResultTemplate",
    RESULT_REPORT_TEMPLATE_DELETE:"/resultTemplate/deleteResultTemplate",
    //日志管理
    OPER_LOG_LIST:"/monitor/operlog/list"
  },
};

// 响应状态码
export const HTTP_STATUS = {
  SUCCESS: 200,
  CREATED: 201,
  NO_CONTENT: 204,
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  INTERNAL_ERROR: 500,
};

// 业务状态码
export const BUSINESS_CODE = {
  SUCCESS: 200,
  FAIL: 500,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,
  VALIDATION_ERROR: 422,
};

// 导出服务器配置，方便调试
export { SERVER_CONFIG, getServerConfig, buildBaseUrl };
